#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Predesys Server - Error Log - Error Log module
@version: 0.2.5
@license: GPL 3.0 (see "license" file)
@author: Jose A. Jimenez
@contact: jajimc@gmail.com"""

import sys
sys.dont_write_bytecode = True
import logging
import logging.handlers

def log_exception(message, area):
    """Logs a new exception message.
    @param message: Message
    @type message: C{str}
    @param area: Predesys area where exception occurred
    @type area: C{str}"""
    if message == None or type(message) != str: return
    if area == None or type(area) != str: return
    
    try:
        rootLogger = logging.getLogger("")
        rootLogger.setLevel(logging.DEBUG)
        socketHandler = logging.handlers.SocketHandler("localhost", logging.handlers.DEFAULT_TCP_LOGGING_PORT)
        rootLogger.addHandler(socketHandler)
        
        logger = logging.getLogger(area)
        logger.error(message)
    except:
        pass
